package com.qf.hospital.controller;

import com.qf.hospital.entity.SysUser;
import com.qf.hospital.service.SysUserService;
import com.qf.hospital.vo.SideVO;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zjw
 * @description 侧边栏Controller
 * @date 2021/10/15 17:22
 */
@RestController
public class SideController {

    private Logger log = LoggerFactory.getLogger(SideController.class);


    @Autowired
    private SysUserService sysUserService;
    /**
     * 查询侧边栏
     * @return
     */
    @GetMapping("/side")
    public List<SideVO> side(){
        //1. 获取当前登录用户的id
        Subject subject = SecurityUtils.getSubject();
        SysUser sysUser = (SysUser) subject.getPrincipal();
        if(sysUser == null){
            log.info("【侧边栏】 用户已经登录超时！");
            return  null;
        }
        Integer userId = sysUser.getUserId();

        //2. 调用Service查询数据
        List<SideVO> result = sysUserService.findSideByUserId(userId);

        //3. 返回
        return result;
    }

}
